<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../412/lib/vue.js"></script>
</head>

<body>
    <div id="app">
        <h2>{{title}}</h2>
        <h2>money --- {{money | monFormat(5,"$")}}</h2>
    </div>
    <script>
        Vue.filter("monFormat", (value, n, str) => {
            if (!value) return ''
            //人民币  美元
            if (str == '$') {
                //美元
                value = value * 0.1579
                n = n || 3
                value = (value * 1).toFixed(n)
                //取余加千分位
                value1 = (value % 1).toFixed(n) // 小数
                value3 = value1.substr(1, n + 1);
                value2 = "" + (value - value1) // 整数
                return value2.replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, '$&,') + value3
            } else {
                //人民币
                n = n || 3
                value = (value * 1).toFixed(n)
                //取余加千分位
                //首先去掉小数
                value1 = (value % 1).toFixed(n) // 小数
                value3 = value1.substr(1, n + 1);
                value2 = "" + (value - value1) // 整数
                return value2.replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, '$&,') + value3
            }
        })
        const vm = new Vue({
            data: {
                title: "filter",
                money: 32843113283.231132
            },
            mounted() {
                document.getElementsByTagName("title")[0].innerHTML = this.title;
            }
        }).$mount("#app");
    </script>
</body>

</html>